package prac6;
/**
 * Student class.
 * 
 * @author Brendon Taylor
 *         Brendon Taylor (Feb 2010) - JavaDoc
 * @since  August, 2009
 */
public class Student {
	/** ID of the student */
	private long studentID;
	/** First name of the student */
	private String firstName;
	/** Last name of the student */
	private String lastName;
	/** Subjects the student is enrolled in */
	private LinkedSet<Subject> subjects;
	
	/** Keeps track of the next student ID */
	public static int nextStudentID = 2 * (int)Math.pow(10, 9);
	
	/**
	 * @param       firstName of the student
	 * @param       lastName of the student
	 * @complexity  O(1)
	 */
	public Student(String firstName, String lastName) {
		setStudentID(nextStudentID++);
		setFirstName(firstName);
		setLastName(lastName);
		subjects = new LinkedSet<Subject>();
	}
	
	/**
	 * Enrolls a student to a subject. 
	 * 
	 * @param       subject to add
	 * @complexity  best case: O(F)
	 *              worst case: O(F+A)
	 *              where F is the complexity of {@link LinkedSet#isMember(Object)}
	 *                    A is the complexity of {@link LinkedSet#add(Object)}
	 */
	public void enrollSubject(Subject subject) {
		if (!subjects.isMember(subject))
			subjects.add(subject);
	}
	
	/**
	 * Unrolls a student from a subject.
	 * 
	 * @param       subject to unroll from
	 * @return      whether the operation was successful
	 * @complexity  best and worst case: O(D)
	 *              where D is the complexity of {@link LinkedSet#deleteItem(Object)}
	 */
	public boolean unrollSubject(Subject subject) {
		return subjects.deleteItem(subject);
	}
	
	public LinkedSet<Subject> intersection(Student otherStudent) {
		return subjects.intersection(otherStudent.subjects);
	}
	
    //	public LinkedSet<Subject> union(Student otherStudent) {
    //		return subjects.union(otherStudent.subjects);
    //	}
	
	public boolean hasSubjects(LinkedSet<Subject> subjects) {
		return this.subjects.equals(subjects);
	}
	
	/* *************** ACCESSORS / MUTATORS **************** */
	
	/**
	 * @param       studentID the studentID to set
	 * @complexity  best and worst case: O(1)
	 */
	public void setStudentID(long studentID) {
		this.studentID = studentID;
	}

	/**
	 * @return      the studentID
	 * @complexity  best and worst case: O(1)
	 */
	public long getStudentID() {
		return studentID;
	}

	/**
	 * @param       firstName the firstName to set
	 * @complexity  best and worst case: O(1)
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return      the firstName
	 * @complexity  best and worst case: O(1)
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param       lastName the lastName to set
	 * @complexity  best and worst case: O(1)
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return      the lastName
	 * @complexity  best and worst case: O(1)
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @return      the full name
	 * @complexity  best and worst case: O(1)
	 */
	public String getFullName() {
		return getFirstName() + " " + getLastName();
	}

	/* ***************************************************** */	
}